using System;
using System.Diagnostics;
using System.ServiceModel;
using System.Threading;
using Lab620.WcfRadiusService.Extentions;

namespace Lab620.WcfRadiusService
{
    internal class RadiusServiceConsoleHost
    {
        private static void ServiceFromConfig()
        {
            Console.Out.WriteLine("Running RADIUS Server From Config.");
            var service = new ServiceHost(typeof (AuthenticationService));
            foreach(var endpoint in service.Description.Endpoints)
            {
                if (endpoint.ListenUri.Scheme.Contains("udp"))
                endpoint.Behaviors.Add(new RadiusValidationBehavior());
            }
            service.Open();

            Console.WriteLine("Service is started from config...");
            Console.WriteLine("Press <ENTER> to terminate the service and exit...");
            Console.ReadLine();
            service.Close();
        }

        private static void Main(string[] args)
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
            ServiceFromConfig();
        }
    }
}